﻿using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;

namespace Sustainalytics.Auth.Service.Tests
{
    public static class ResponseExtensions
    {
        public static void ShouldBeErrorResponse(this HttpResponseMessage response, string errorDescription)
        {
            response.ShouldBeErrorResponse("invalid_client", errorDescription);
        }

        public static void ShouldBeErrorResponse(this HttpResponseMessage response, string error, string errorDescription)
        {
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var errorResponse = response.Content.ReadAsAsync<ErrorResponse>().Result;
            errorResponse.Error.Should().Be(error);
            errorResponse.ErrorDescription.Should().Be(errorDescription);
        }

        public static void ShouldBeTokenResponse(this HttpResponseMessage response)
        {
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var tokenResponse = response.Content.ReadAsAsync<TokenResponse>().Result;

            tokenResponse.AccessToken.Should().NotBeEmpty();
            tokenResponse.RefreshToken.Should().NotBeEmpty();
        }
    }
}
